<%@page import="com.system.dao.UserDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../common.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ui" uri="http://com.am.tag" %>
<%
	UserDao dao = new UserDao();
	List<Map<String,Object>> list = dao.getCheckPrivildegeUsers();
	pageContext.setAttribute("list", list);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'userEdit.jsp' starting page</title>
    <link rel="stylesheet" href="${path}/css/showtable.css" type="text/css"></link>
    <link rel="stylesheet" type="text/css" href="${path}/css/easyui.css">
    <script type="text/javascript" src="${path}/js/public/grid.js"></script>
    <script type="text/javascript" src="${path}/js/public/jquery.easyui.min.js"></script>
    <script type="text/javascript">
    
    	$(function(){
    		$("#company").attr("style","display:none;");
    		$("#useways").change(function(){
           		if($(this).val()=='3'){
           			$("#company").attr("style","").attr("show","y");
           		}else{
           			$("#company").attr("style","display:none;").attr("show","n");
           			$("#choCompany").val("");
           		}
           	});
    	});

		function changeStyle(obj,flag)
		{
			flag ? $(obj).css("background-color","#ffff99") : $(obj).css("background-color","");
		}
		 
		var arr = new Array();
  		var i = 0; 
  		function addRow(records){
			/*if(!isSelectOne(mygrid))
			{
				alert("请选择一条记录进行添加");
				return;
			}*/
			
			for(var k=0;k<records.length;k++){
				var record = records[k];
				if(checkRecord(record)){
					var innerHTML = "<tr onmouseover='changeStyle(this,true)' onmouseout='changeStyle(this,false)' id='"+record['id']+"'>";
					innerHTML += "<td style='display:none;'>"+record['id']+"</td>";
					innerHTML += "<td>"+record['name']+"</td>";
					innerHTML += "<td>"+record['vender']+"</td>";
					innerHTML += "<td id='num"+record['id']+"' align='center'>"+record['drug_num']+"</td>";
					innerHTML += "<td><input id='value"+record['id']+"' name='name"+record['id']+"' type='text' class='textbox'></td>";
					innerHTML += "<td align='center'><a href='javascript:void(0)' onclick='delRow("+record['id']+");'>删除</a></td>";
					innerHTML += "</tr>";
					$(".showtable").append(innerHTML);
					arr[i] = record['id'];
					i++;
				}
			}
			chooseDrug.mygrid.reload(); //刷新表格
  		}

  		function checkRecord(record){
  			for(var j in arr){
				if(arr[j] == record['id']){
					//alert(record['name'] + "该记录已经存在已选表中");
					return false;
				};
			};
			return true;
  		}
  		function delRow(idIndex){
  			//$(this).parent().parent().remove();
  			$("tr[id='" + idIndex + "']").remove();//删除当前行
			for(var j in arr){
				if(arr[j] == idIndex){
					arr.splice(j,1);
					return;
				};
			};
  		}
    	
		 
  		function doSave(){
  	    	var approve_user_name = $("#approve_user").find("option:selected").text();
    		if(doCheck() && confirm("确认提交审核吗？")){
    			var map = Form.formToBean("winForm");
        		map.arr = arr;
        		map.style = 1;
        		map.approve_user_name = approve_user_name;
        		ajax.remoteCall("com.system.dao.DrugDao:insertResult",[map],function(reply){
        			var result = reply.getResult();
        			alert(result.value);
        			if(result.type == "success"){
        	    		var dlg = Dialog.getInstance("view");
        	    		dlg.getParam("window").mygrid.reload();
        	    		dlg.close();
        			}
        		});
    		}
    		
    	}
    	
    	function doCheck(){
    		var regExp = /^[0-9]*$/;
    		//var regExp = /^[0-9]*[1-9][0-9]*$/;
    		
    		if(arr.length == 0){
    			alert("请选择药品");
    			return false;
	    	}
	    	
	    	if($("#approve_user").val()==''){
	    		alert("请选择审核人");
    			return false;
	    	}
	    	
	    	if($("#useways").val()==''){
	    		alert("请选择出库方式");
    			return false;
	    	}
	    	
	    	if($("#company").attr("show")=='y' && $("#choCompany").val()==''){
	    		alert("请选择药品公司");
    			return false;
	    	}
	    	
	    	if($.trim($("#remark").val())==''){
	    		alert("备注不能为空");
    			return false;
	    	}
	    	
    		for(var j=0;j<arr.length;j++){
    		
    			if(arr[j] != ""){
    		
					var usenum = parseInt($.trim($("#value"+arr[j]).val()));
					var num = parseInt($.trim($("#num"+arr[j]).html()));
		    		if(usenum == ""){
		    			alert("提取数量不能为空");
		    			return false;
		    		}
		    		if(usenum > num){
		    			alert("提取数量不能大于库存数");
		    			return false;
		    		}
		    		
		   			if((!regExp.test(usenum))){
		   				if(usenum == '0'){
		   					return true;
		   				}
		   				alert("请输入正整数");
		    			return false;
		   			}
    			}
			};
    		
    		return true;
    	}
    	
    </script>
	<style type="text/css">
		a:link {
			text-decoration: none;
		}
		
		a:visited {
			text-decoration: none;
		}
		
		a:active {
			text-decoration: none;
		}
		
		a:hover {
			text-decoration: none;
		}
		
		.mywindowTitle {
			font-weight: bold
		}
	</style>
  </head>
  
  <body style="overflow-x: hidden">
   <form id="winForm" name="winForm">
   		<input name="userId" type="hidden" value="${currentUserId}">
   		<input name="userName" type="hidden" value="${currentUserName}">
   		<input name="userCampus" type="hidden" value="${currentUserCampus}">
   		<div style="padding:10px;width:600;height:500">	
   			<input name="id" type="hidden" value="${param.id}">
	  		<table>
	  			<tr>
					<td valign="top" align="left">
						<font color='#3A5FCD' size='2' style="font-family: '微软雅黑', Verdana, Arial, Helvetica, sans-serif;"><b>基本信息</b></font>
						<hr/>
	  				</td>
				</tr>
				<tr>
					<td valign="top" align="left">
						<div style="padding-right:10px;padding-left:10px;">	
							<table>
								<tr>
									<td valign="middle" align="right" width="100">
										姓名:
									</td>
									<td width="100">
										<input name="name" id="name" class="textbox" value="${currentUserName}" readonly="readonly" style="color: blue;"/>
									</td>
									<td valign="middle" align="right" width="150">
										<font color="#FF0000">*</font>审核人:
									</td>
									<td width="100">
										<select name="approve_user_id" id="approve_user">
											<option value="">---请选择审核人---</option>
											<c:forEach items="${list}" var="obj">
												<option value="${obj.id}">${obj.name }</option>
											</c:forEach>
										</select>
									</td >
									<td valign="middle" align="right" width="250">
										<font color="#FF0000">*</font>出库方式:
									</td>
									<td align="right" width="100">
										<select name="type" id="useways">
											<option value="">---请选择方式---</option>
											<option value="0">领用</option>
											<option value="1">至药房</option>
											<option value="2">损坏</option>
											<option value="3">退药</option>
										</select>
									</td>
								</tr>
							</table>
							<table id="company">
								<tr>
									<td valign="middle" align="right">
										<font color="#FF0000">*</font>&nbsp;&nbsp;公司:
									</td>
									<td align="left" width="100">
										<ui:select pvalue="MedicalCompany" name="outCompany" id="choCompany" style="width: 125"/>
									</td>
								</tr>
							</table>
							<table>
								<tr>
									<td valign="middle" align="right" width="100">
										<font color="#FF0000">*</font>备注:
									</td>
									<td valign="middle">
										<textarea id="remark" name="notes" style="width:513;height:50"></textarea>
									</td>
								</tr>
								<tr>
									<td width="120px" align="right"><img src="${path}/images/tip.png" border="0" width="20px" height="15px" /></td>
									<td valign="middle" height="30"><font color="green" style="font-size: 9.5px">温馨提示：请注意选择审核人和出库方式是否正确，备注不能为空！</font></td>
								</tr>
							</table>
						</div>
	  				</td>
				</tr>
				<tr>
					<td valign="top" align="left">
						<font color='#3A5FCD' size='2' style="font-family: '微软雅黑', Verdana, Arial, Helvetica, sans-serif;"><b>选择药品</b></font>
						<hr/>
	  				</td>
				</tr>
				<tr>
					<td valign="top" align="left">
						<div style="padding-right:10px;padding-left:10px;width:580;height:200">	
							<iframe frameborder="0" width="100%"  height="100%" name="chooseDrug" src="chooseDrug.jsp" scrolling="no" ></iframe>
	  					</div>
	  				</td>
				</tr>
				<tr>
					<td valign="top" align="left">
						<font color='#3A5FCD' size='2' style="font-family: '微软雅黑', Verdana, Arial, Helvetica, sans-serif;"><b>已选药品</b></font>
						<font color="red" style="font-size: 9.5px">（温馨提示：不重复添加相同的药品！）</font>
						<hr/>
	  				</td>
				</tr>
				<tr>
					<td valign="top" align="left">
						<div style="padding-right:10px;padding-left:10px;">	
						<table class="showtable">
							<tr>
								<th width="20%">药品名称</th>
								<th width="20%">厂家名称</th>
								<th width="10%">库存</th>
								<th width="10%">提取数量</th>
								<th width="10%">操作</th>
							</tr>
						</table>
						</div>
	  				</td>
				</tr>
	  		</table>
  		</div>
	</form>
  </body>
</html>
